import fetch from 'common/src/utils/fetch';
import utils from 'common/src/utils/utils';
import cryp from  'common/src/utils/secret';

/**
 * 课程类别查询
 */
export function queryCourseTypeList(params) {
    let query = '?';
    for (let key in params) {
        query += key;
        query += '=';
        query += params[key];
        query += '&';
    }
    return fetch({
        url:
            '/api/cultureservice/minorCultureRule/minorCoursesLabelList' +
            query.substring(0, query.length - 1),
        method: 'GET'
    });
}
/**
 * 课程设置查询
 */
export function minorMinorCourseLabelRelationList(params) {
    let query = '?';
    for (let key in params) {
        query += key;
        query += '=';
        query += params[key];
        query += '&';
    }
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelation/minorMinorCourseLabelRelationList' +
            query.substring(0, query.length - 1),
        method: 'GET'
    });
}

/**
 * 课程设置保存
 */
export function minorCourseLabelRelation(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelation',
        method: 'PUT',
        data
    });
}

/**
 * 新增课程保存
 */
export function addPreCourse(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelation/batchInsertPrerequisiteCourse',
        method: 'POST',
        data
    });
}
// cultureservice
/**
 * 新增课程保存
 */
export function addCourse(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelation',
        method: 'POST',
        data
    });
}
/**
 * 删除课程
 */
export function deleteCourse(id) {
    return fetch({
        url:
            `/api/cultureservice/minorCourseLabelRelation/${id}`,
        method: 'DELETE',
    });
}

/**
 * 几选几分组保存
 */
export function addDivide(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelGroup/addMinorCourseLabelRelGroup',
        method: 'POST',
        data
    });
}
/**
 * 几选几分组删除
 */
export function deleteDivideGroup(data) {
    return fetch({
        url:
            '/api/cultureservice/minorCourseLabelRelGroup/deleteMinorCourseLabelRelGroup',
        method: 'DELETE',
        data
    });
}

/**
 * 获取章节模板
 */
export function getChapterTemplete(params) {
    let query = '?';
    for (let key in params) {
        query += key;
        query += '=';
        query += params[key];
        query += '&';
    }
    return fetch({
        url:
            '/api/cultureservice/minorCultureSchemeDetail/findCultureOrTemplateChapterContentList' +
            query.substring(0, query.length - 1),
        method: 'GET'
    });
}

/**
 * 章节关联表格保存
 */
export function saveTableDetail(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemeDetail',
        method: 'POST',
        data
    });
}

/**
 * 章节设置保存
 */
export function saveChapter(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureSchemeDetail/upateMinorCultScheDetailOrTemplate',
        method: 'POST',
        data
    });
}
/**
 * 微专业培养计划管理列表
 */
export function findMinorStudentCultureRelList(data) {
    return fetch({
        url: '/api/cultureservice/minorStudentCultureRel/findMinorStudentCultureRelList',
        method: 'POST',
        data
    });
}
/**
 * 微专业培养计划管理-自定义计划基本信息
 */
export function findMinorStudentCulture({ studentId, entranceTerm, byStuSelf }) {
    return fetch({
        url: `/api/cultureservice/minorStudentCultureRel/findMinorStudentCultureRelByStudentId?studentId=${studentId}&entranceTerm=${entranceTerm}&byStuSelf=${byStuSelf}`,
        method: 'GET',
    });
}
/**
 * 微专业培养计划管理-获取方案列表
 */
export function findAllMinorStudentCulture({ studentId }) {
    return fetch({
        url: `/api/cultureservice/minorStudentCultureRel/findMinorStudentCultureRelByStudentId?studentId=${studentId}`,
        method: 'GET',
    });
}
/**
 * 微专业培养计划管理-自定义计划学分完成情况
 */
export function getMinorCulturePlan({ id, entranceTerm, byStuSelf, planType }) {
    return fetch({
        url: `/api/cultureservice/minorCulturePlan/getMinorCulturePlanByStudentId?id=${id}&entranceTerm=${entranceTerm}&byStuSelf=${byStuSelf}&planType=${planType}`,
        method: 'GET',
    });
}
/**
 * 微专业培养计划管理-获取学生图片路径
 */
export function findUserInfoByIdType(id, type) {
    // let params = `userId=${utils.encode64(id)}&type=${utils.encode64(type)}`;
    let params = `userId=${cryp.encrypt(id)}&type=${cryp.encrypt(type)}`;//换用新加密方式
    return fetch({
        url: `/api/studentservice/studentInfo/findUserInfoByIdType?${params}`,
        method: 'GET'
    });
}

/**
 * 微专业培养计划管理-获取学生图片信息
 */
export function downloadimage(photo) {
    return fetch({
        url: `/api/commonservice/obsfile/downloadimage?objectkey=${photo}`,
        method: 'GET'
    });
}

/**
 * 培养计划管理--培养计划制定--保存
 */
export function setCulturePlan(data) {
    return fetch({
        url: `/api/cultureservice/minorCulturePlan/setCulturePlan`,
        method: 'PUT',
        data
    });
}
/**
 * 培养计划管理--培养计划制定--查看培养计划
 */
export function catCulturePlan({ id, type }) {
    return fetch({
        url: `/api/cultureservice/minorCultureSchemeDetail/findCultureOrTemplateChapterContentList?cultureId=${id}&type=${type}`,
        method: 'GET',
    });
}


/**
 * 微专业培养计划管理--操作日志
 */
export function findMinorCultureLogList(data) {
    return fetch({
        url: '/api/cultureservice/minorCultureLog/findMinorCultureLogList',
        method: 'POST',
        data
    });
}
/**
 * 微专业培养计划管理--获取操作日志筛选条件--操作类型
 */
export function getOptionTypeList() {
    return fetch({
        url: '/api/cultureservice/minorCultureLog/getOptionTypeList',
        method: 'GET'
    });
}

/**
 * 微专业培养计划管理--获取操作日志筛选条件--日志下载
 */
export function exportOption(params) {
    let url = '/api/cultureservice/minorCultureLog/exportMinorCultureLogList';
    let query = '?';
    for (let key in params) {
        query += key;
        query += '=';
        query += params[key];
        query += '&';
    }
    return url + query.substring(0, query.length - 1);
}
